/*
 * Parameters.java
 *
 * Created on 7 de Julho de 2011, 17:29
 *
 */

package intopo.demonstrator.partnerselection;

import intopo.demonstrator.Event;
import util.math.Rational;

/**
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 7 de Julho de 2011
 */
public class Parameters
	extends intopo.demonstrator.CommonParameters
	implements Cloneable
{
//	/**
//	 * This value represents the probability of a sucessfull event.
//	 * Probabilities are represented as integers.  In the Monte Carlo
//	 * simulation we take into account the number of bits used to represent
//	 * probability values.
//	 */
//	final int maxProbability;
//	/**
//	 * Size of the partner and combination vectors.
//	 */
//	final int poolSize;
//	/**
//	 * Multiplication factor used when a probability is decreased because
//	 * an unacceptable partner combination was chosen.
//	 * This field represents parameter <i>&delta;</i> mentioned in the
//	 * paper.
//	 */
//	final int deltaNumerator;
//	final int deltaDenominator;
	/**
	 * Probability that a partner combination is acceptable.  When a
	 * selected partner combination is not acceptable, it is replaced.  Its
	 * slot in the combination vector has a new partner combination.  The value should be interpreted as {@code (2^31+acceptableProbability)/2^32}
	 */
	Event behaveAcceptably;
	/**
	 * Create a default set of parameters.
	 */
	public Parameters ()
	{
		this (3, 4, new Rational (1), new Rational (1, 2));
	}
	/**
	 * Creates a new instance of Parameters
	 */
	public Parameters (int numberBitsProbability, int poolSize, Rational delta, Rational acceptableProbability)
		throws IllegalArgumentException
	{
		super (numberBitsProbability, poolSize, delta);
		this.behaveAcceptably = new Event (1);
		this.setProbabilityDrawAcceptableCombination (acceptableProbability);
	}
	/**
	 * Return the probability to draw an acceptable combination.  This value is stored internally as an integer value.
	 */
	public float probabilityDrawAcceptableCombination ()
	{
		return this.behaveAcceptably.getRawProbability ();
	}
//	/**
//	 * Return the number of bits used to encode probabilities in the
//	 * probability vector.
//	 */
//	public int getNumberBitsProbability ()
//	{
//		return (int) Math.round (Math.log (this.maxProbability + 1) / Math.log (2));
//	}
//	/**
//	 * Sets the number of bits used to encode probabilities in the
//	 * probability vector.
//	 */
//	public void setNumberBitsProbability (int numberBitsProbability)
//		throws IllegalArgumentException
//	{
//		if (numberBitsProbability < 1) {
//			throw new IllegalArgumentException ("The number of bits used to encode probabilities in the probability vector must be strictly positive");
//		}
////		this.maxProbability = (int) Math.pow (2, numberBitsProbability);
//	}
//	public int getMaxProbability ()
//	{
//		return this.maxProbability;
//	}
//
//	public int getDeltaDenominator ()
//	{
//		return deltaDenominator;
//	}
//
//	public int getDeltaNumerator ()
//	{
//		return this.deltaNumerator;
//	}
//	public Rational getDelta ()
//	{
//		return new Rational (this.deltaNumerator, this.deltaDenominator);
//	}
//	public int getPoolSize ()
//	{
//		return this.poolSize;
//	}
	public Rational getProbabilityDrawAcceptableCombination ()
	{
		return this.behaveAcceptably.getProbability ();
	}
	public void setProbabilityDrawAcceptableCombination (Rational p)
	{
		if (p.compareTo (Rational.ZERO) <= 0 || p.compareTo (Rational.ONE) > 0) {
			throw new IllegalArgumentException ("Probability to draw acceptable combinations must be greater than zero and less than or equal to one");
		}
		this.behaveAcceptably.setProbability (p);
	}
}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
